<?php
/*
 * emarket - a website to create your own online-shop.  
 * Copyright (C) 2009  Frédéric Delorme
 *
 * This file is part of emarket.
 *
 * emarket is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * emarket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with emarket.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact me: frederic.delorme@gmail.com
 * to see some information on te project : http://code.google.col/p/os-emarket/
 *
 */
/**
 * Ajax class to generate ajax commands inline of template files.
 * @author frederic
 *
 */
class Ajax{
	/**
	 * convert php array into json array for Ajax options.
	 * @param $option
	 * @return string
	 */
	public function jsonOptions($options=array()){
		return (!empty($options)?",{}":"");
	}
	/**
	 * create a javascript call to the prototype Ajax component.
	 * @param $url url of the php treatment
	 * @param $target part of the page to be repainted
	 * @param $options options to input to Ajax.
	 * @return string containing the well formed javascript call.
	 */
	public function remote($target,$url,$options){
		return "new Ajax.Updater('$target','$url&ajax'".self::jsonOptions($options).");";
	}
	
	/**
	 * Integrate a remote call into a generated javascript event.
	 * @param $url URL to be called for treatment
	 * @param $target DOM element target to be refresh with teh resulting treatement.
	 * @param $options some Prototype::Ajax object options.
	 * @return unknown_type
	 */
	public function jsRemoteCall($url, $target, $options){
		return "javascript:".self::remote($target,$url,$options);
	}
}
?>